/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author IT-Mafia
 */
@Entity
@Table(name = "rbh_risk_role")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@XmlRootElement
public class Role implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ROLE_ID", unique = true, nullable = false, columnDefinition = "tinyint UNSIGNED")
    private Byte roleId;
    @Column(name = "ROLE_NAME", unique = true, nullable = false, length = 100)
    private String roleName;
    @Column(name = "ROLE_NAME_TH", unique = true, nullable = false, length = 100)
    private String roleNameTH;
    @Basic(optional = false)
    @Column(name = "ROLE_ORDER_NUMBER", columnDefinition = "tinyint UNSIGNED default 0", nullable = false)
    private short roleOrderNumber;
    @Basic(optional = false)
    @Column(name = "ROLE_STATUS", columnDefinition = "boolean default true", nullable = false)
    private boolean roleStatus;
    @Column(name = "ROLE_DESCRIPTION", length = 1024)
    private String roleDescription;
    @OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<Profile> profileList;
    @OneToMany(mappedBy = "role", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<Privilege> privilegeList;

    public Role() {
    }

    public Role(Byte roleId) {
        this.roleId = roleId;
    }

    public Role(Byte roleId, String roleName) {
        this.roleId = roleId;
        this.roleName = roleName;
    }

    public Byte getRoleId() {
        return roleId;
    }

    public void setRoleId(Byte roleId) {
        this.roleId = roleId;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getRoleNameTH() {
        return roleNameTH;
    }

    public void setRoleNameTH(String roleNameTH) {
        this.roleNameTH = roleNameTH;
    }

    public boolean isRoleStatus() {
        return roleStatus;
    }

    public void setRoleStatus(boolean roleStatus) {
        this.roleStatus = roleStatus;
    }

    public String getRoleDescription() {
        return roleDescription;
    }

    public void setRoleDescription(String roleDescription) {
        this.roleDescription = roleDescription;
    }

    public List<Profile> getProfileList() {
        return profileList;
    }

    public void setProfileList(List<Profile> profileList) {
        this.profileList = profileList;
    }

    public List<Privilege> getPrivilegeList() {
        return privilegeList;
    }

    public void setPrivilegeList(List<Privilege> privilegeList) {
        this.privilegeList = privilegeList;
    }

    public short getRoleOrderNumber() {
        return roleOrderNumber;
    }

    public void setRoleOrderNumber(short roleOrderNumber) {
        this.roleOrderNumber = roleOrderNumber;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (roleId != null ? roleId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.roleId == null && other.roleId != null) || (this.roleId != null && !this.roleId.equals(other.roleId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rbh.risk.entity.Role[ roleId=" + roleId + " ]";
    }
}
